Thursday 15 August 2013

javascript - Writing .htm file name to the contents of the file in HTML -



javascript - Writing .htm file name to the contents of the file in HTML -

e.g. have file named: page1.htm

in html need show link google result of search file name. i.e.:

https://www.google.co.uk/?gfe_rd=cr&ei=6mhcvogvhmnh8gej8ocqdq&gws_rd=ssl#q=page1

obviously if need lots of pages, easier if there way amend end of search string depend on filename (without extension).

please tell me there simple way produce result!

thanks

because serving static html page, 'active' behavior, (like automatically reusing file's name in content) need happen @ runtime on client side. means javascript:

<!-- in html, utilize id tag create link selectable javascript...--> <a id="googlesearchlink" href="#">search google name of file</a>

then @ bottom of body content (so happens after tag rendered) add:

<script> // grab after lastly "/" location bar... var filename = window.location.href.substr(window.location.href.lastindexof("/")+1); // chop off lastly "." , right of it... var withoutextension = filename.replace(/\.[^/.]+$/, ""); // build link destination string... var hreftargetforgooglelink = "https://www.google.co.uk/#q=" + withoutextension; // finally, set link destination googlesearchlink.href = hreftargetforgooglelink; </script>

javascript html html5 filenames

No comments:

Post a Comment