-3

Due to an issue that came up with a website I have to use javascript for all of the links on the page.

like so...

<a href="javascript:this.location = 'stamping.html'"><img src="image.png"/></a>

Will having many links with javascript on the webpage slow it down significantly?

Does the Javascript run when the page initially loads or only when a link is clicked?

EDIT: For those asking why I'm doing this. I'm creating an iPad site, when you use the 'add to home page' button to add the site as an icon, it allows users to view the site with no address bar.

However everytime a link is clicked it reopens Safari in a new window with the address bar back.

The only solution I could find was using javascript instead of an html based link to open the page.

For further reference see...

iPad WebApp Full Screen in Safari

2nd answer

"It only opens the first (bookmarked) page full screen. Any next page will be opened WITH the address bar visible again. Whatever meta tag you put into your page header..."

3rd answer down

"If you want to stay in a browser without launching a new window use this HTML code:

a href="javascript:this.location = 'index.php?page=1'"

"

Community
  • 1
  • 1
Philip Kirkbride
  • 21,381
  • 38
  • 125
  • 225

2 Answers2

0

I can see this adding to the bandwidth needs of a site marginally (very marginally), but the render time and the response time on clicking shouldn't be noticeable.

If it is a large concern I would recommend benchmarking the two different approaches to compare the real impact.

Rontologist
  • 3,568
  • 1
  • 20
  • 23
  • Was wondering if the javascript in all the links would be run on initial page load or only when clicked, that seems like it would make a big difference. – Philip Kirkbride Sep 14 '11 at 22:20
  • 1
    It's only ran when it's clicked. There may be some extra parsing cost but that too wouldn't be noticeable. – Rontologist Sep 14 '11 at 22:25
0

What do you mean by slow it down?

Page load time? Depends on the number of links on your page. It would have to be a LOT to be noticeable. Execution time? Again, not noticeable.

The better question to ask is are you o.k. with effectively deleting your website for those without javascript?

Also, if you are worried about SEO, you will need to take additional measures to ensure your site can still be indexed. (I doubt Google follows those kinds of URLs... could be wrong I guess).


EDIT: Now that you explained your situation above, you could easily just "hide" the address bar. See this SO question.

Community
  • 1
  • 1
simshaun
  • 21,263
  • 1
  • 57
  • 73
  • Well I don't know if the javascript is run on loading the page or only when the link is clicked... that would make a big difference. – Philip Kirkbride Sep 14 '11 at 22:19
  • I already am using that meta-tag on all my pages. It works for first bookmarked page but links open in a new Safari window with address bar back again. Read the 3rd answer down quote I added to my question. – Philip Kirkbride Sep 14 '11 at 22:54