473,385 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Javascript outerHTML - Shows text on new blank page - Problem

3
Hi Guys,

i'm having a problem with a little Javascript in a link


Sorry that it is all in a line but it is actually a link. Please wrap.

This results in a new page with only "Initially processing" showing
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:var Aobj = document.getElementsByTagName('span'); for (var i = 0;i &lt; Aobj.length;i++) { if (Aobj[i].className === 'SLA') { Aobj[i].innerHTML += 'Initially processing'; Aobj[i + 1].innerHTML = ''; } }"><br/>Read more</a>
This (alert added) results in a correct output. But i don't want an alert.
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:var Aobj = document.getElementsByTagName('span'); for (var i = 0;i &lt; Aobj.length;i++) { if (Aobj[i].className === 'SLA') { Aobj[i].innerHTML += 'Initially processing'; Aobj[i + 1].innerHTML = ''; alert("stop") } }"><br/>Read more</a>
This (whateverbla added) results in an error but executes correctly.
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:var Aobj = document.getElementsByTagName('span'); for (var i = 0;i &lt; Aobj.length;i++) { if (Aobj[i].className === 'SLA') { Aobj[i].innerHTML += 'Initially processing'; Aobj[i + 1].innerHTML = ''; whateverbla } }"><br/>Read more</a>

Can you tell me if i am doing anything wrong or tell me what i could do to stop executing (break results in empty page only).
I can not exclude that the error is somewhere else because i am working in a company corporate portal environment and i don't control everything there.


Thanks in advance and
best Regards

Marcel
Nov 3 '08 #1
5 2484
acoder
16,027 Expert Mod 8TB
It's caused by the href attribute. You need to cancel it if you want to prevent a new page being loaded. What you can do is use onclick instead, e.g.
Expand|Select|Wrap|Line Numbers
  1. <a href="#" onclick="var Aobj = document.getElementsByTagName('span'); for (var i = 0;i < Aobj.length;i++) { if (Aobj[i].className === 'SLA') { Aobj[i].innerHTML += 'Initially processing'; Aobj[i + 1].innerHTML = ''; } }; return false;"><br/>Read more</a>
or declare a function with this code and call that instead.
Nov 3 '08 #2
Maize
3
Thanks for the answer. Exactly what i was looking for.

But the editor in the corporate portal removes any javascript and also removes the "onclick" tag in the link before publishing my html. (not in the href part for some reason). This is due to some security issues.

If you know any workarounds let me know. If not, its ok. The answer already helped me a lot.

Thanks and Regards
Marcel
Nov 4 '08 #3
acoder
16,027 Expert Mod 8TB
Yes, there is. Add void(0) or void 0 at the end in the href. That should solve your problem. Of course, I would recommend using the onclick as best practice and you should avoid the "javascript:" protocol in the href attribute, but I guess your hands are tied.
Nov 4 '08 #4
Maize
3
Hi acoder,

that totally did it. Thanks a lot, i'll try not to use it if it is not
necessary but in this case, yes, my hands are tied and i am
happy to have found this solution with your help.

Thanks and Regards
Maize
Nov 4 '08 #5
acoder
16,027 Expert Mod 8TB
You're welcome. Glad to help :)
Nov 4 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dariusz | last post by:
I have a problem with a call a Javascript "window.open()" function which is executed as part of a PHP file when a user clicks on an thumbnail image. The PHP is executed which passes some variables...
7
by: Marci | last post by:
I found this script for cascading menus, however, I cannot reach the author to solve the bug I am having when I add a second menu to it. My problem is this: If I click on the first link, the...
2
by: thinkfr33ly | last post by:
I have a page that inserts a block of javascript dynamically into the page "Test.html". The inserted block, "Block A", then does a document.write of another script block "Block B". This script...
1
by: prasaddevivara | last post by:
I am using the outerHTML property to modify the HTML of existin elements in a web page in Internet Explorer. But same outerHTM property is not working in firefox browser, Anybody can tell me a...
8
by: Andrew Phillipo | last post by:
I have a layout which works perfectly. It is three column, the central column is width:auto; with margins and the columns are absolutely positioned at top:0px; left:0px; and top:0px;right:0px; ...
2
by: FatBo | last post by:
Dear all, I am writing a Javascript which print a page without prompting the print dialog when the page is loaded. However, there is a warning box prompted out because I am requesting the...
7
by: e | last post by:
I've been having an extremely difficult time finding an answer to this in IE / js groups, so I thought I'd try here. I've got an aspx page that delivers loads of report data into custom-named...
6
by: kpmassey | last post by:
I am trying to use wget to retrieve web pages like this: http://www.michigan-football.com/s/2006/cascades.htm Visit it and view source to see the obfuscated javascript. Is there any tool to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.