Home › Forums › JavaScript › how extract title from link and place into other page on click event using jquery
- This topic is empty.
-
AuthorPosts
-
March 4, 2013 at 4:52 am #43123
pranavpatil19
Member1)i have two page abc. html and xyz .html
in abc.html i place a link
2) in xyz .html
but i cant extract title from that link and place it into div tag pf xyz.html page ..on same click event how can i do that please help me
here i just want to give name of my video…..if this not work plese telll onother meth0d
March 4, 2013 at 6:51 am #126842JohnMotylJr
ParticipantNot too sure what the pros would do but i got a SUPER SIMPLE solution. If you just need a title from an element to a different page that’s too easy:
The html
<a title="dasdasdadad" href="xyz.html?http://www.youtube.com/embed/Aw03bV9mlQU">dadad</a>
Get the title
var getTitle = function(el) {
return $(el).attr('title');
};
getTitle('a');
// returns 'dasdasdadad'Next take that data and set it into local storage
window.localStorage.setItem('title',getTitle('a'));
var s = window.localStorage.getItem('title');On your xyz.html page call your stored data
var new_title = window.localStorage.getItem('title');
$(element).attr('title', new_title);One last thing, im not really sure what your code above is trying to do since some is in pre/code and some aren’t. I suggest making a use-case, like Code Pen, that way others can clearly see the code you are having trouble with.
March 4, 2013 at 1:20 pm #126876pranavpatil19
Memberhttp://www.sendspace.com/file/fuqrcm <=== download my demo file
or
http://www.megafileupload.com/en/file/398577/chek-this-code-zip.htmlplease check whre i am wrong. in index.html page .i click on link..then this redirecrt me to a.html
at click event video load in iframe but my link title not load in div tag .div tag presnt in a.html
March 4, 2013 at 6:43 pm #126935JohnMotylJr
ParticipantNot 100% if this is what you wanted but what I did here was:
- Cleaned your code up
- Added a link to jQuery
- Created a function to get the anchor tag title attribute
- Parsed the anchor tag to extract only the youtube link (everything AFTER the
?
) - Stored both values into local storage
- On second page created a function to get and set the new attributes for your iframe
- ** i heavily commented the code **
If you need anything further feel free to give me a hollar. Below is a link to the corrections with the same files ( index.html && a.html ).
Download link for: Your finished codeMarch 5, 2013 at 3:39 am #126980pranavpatil19
Memberproblem accor..
check this code where i wrong
http://www.sendspace.com/file/6tl3x6in my second page contain attribute have title tag
whaen i run this code all title present in webpage attribute show
what can i do now.. i just tryind to change title atttriblte to titl and change according to jquery put it cant help ..i got mesage undefined
March 5, 2013 at 8:30 pm #127111JohnMotylJr
ParticipantSolutions by file:
index.html
- Line *: Try using some kind of text editor so you dont have crazy amounts of white space and tabs. Indentation is important because:
a. Clean and readable
b. Easily shows parent/child relationship
- Line 5: Try loading your script files into the head or at least bottom of the body. They are being wrapped in the html element.
- Line 6: In HTML5 there is no need to include
type="text/javascript"
in your script tags. - Line 17: Missing a closing
</nav>
tag. - Line 12: Suggest maybe changing the anchor’s
id="titl"
into something more semantic or at least, less confusing. ieid="youtube-link"
- Line 12: a tag cannot have a property of titl, change to title=””.
- Line 12: Your anchor tag includes two divs and one img (Not saying we cant work around having content clickable).
- Line 12:
data-iframe="true"
is kind of redundant and not needed. - Line 12: Rather then using
<data-title="The Huner <small>Video Opens in ColorBox</small>"
try using title=””. - Line 15: You are using the same title over. You could always leave the title blank and have a possible jQuery solution:
$('a').attr('title', 'Video opens in ColorBox');
Permitted parent elements
Any element that can contain phrasing elements, any element that can contain flow elements
Source: W3C
What shouldn’t I use data attributes for?
Although flexible, data attributes aren’t an appropriate solution for all problems.
Data attributes should not be used if there is a existing attribute or element which is more appropriate for storing your data. For example, date/time data should probably be presented semantically in a time element instead rather than stored in custom data attributes.
Source: HTML5 Doctor
a.js
- Line 8: Spelled title incorrectly, try
return $(el).attr('title');
output.html
- Line *: Good practice to refrain from CAPITALIZING some of your tags, stick to lowercase all around.
- Line 18: List elements are formed without
<ul>
or<ol>
.
b.js
- Line 23: Missing semicolon;
Other suggestions!
- For your example, it wouldn’t hurt to just have one(1) javascript file that both your pages link to.
- In order to not throw any errors & you have local videos to add, you can use the
<video><video>
tags. An iframe cannot set MIME types.
Download the latest code.
March 7, 2013 at 10:22 am #127314pranavpatil19
Memberthis is code work only for link1
when i enter anothr link on the index page..
every time first video is playing…this code work only for link1 ..
March 10, 2013 at 6:12 pm #127683pranavpatil19
Memberhey hi
you actually help me , topic is how extract title from link and place into other page on click event using jquery
you send me a complete code…. but in that code have one bug
this code work only for link 1
when i type 2nd url and click on second url….. video of first url is start playing…why this happen
check this=> just add second link in index.html and provide new video link and click on second link.. you will understand what is error
http://cloud.johnmotyljr.com/demos/pranavpatil19/Code_Complete_2.zipMarch 10, 2013 at 9:32 pm #127695JohnMotylJr
ParticipantYou need to understand why it is not working, hence, look into jQuery selectors.
March 11, 2013 at 2:51 am #127710pranavpatil19
Memberi tried but its not help me…please help me
-
AuthorPosts
- The forum ‘JavaScript’ is closed to new topics and replies.