473,654 Members | 3,072 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript outerHTML - Shows text on new blank page - Problem

3 New Member
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 2493
acoder
16,027 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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 New Member
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 Recognized Expert Moderator MVP
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
3399
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 to Javascript to execute the new window opening. But as it does this, the main window is loaded which is blank (the browser URL bar shows the URL of the URL passed to the PHP / Javascript script). I would like to keep the gallery page visible...
7
2713
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 menu displays well. If I then click on the second link, the first menu from the first link still displays. How do I get make the first menu disappear when I click on the second and vice versa? Please help...thanks.
2
2053
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 block does its own document.write of one last script block "Block C". The way this occurs is somewhat out of my control, and I need to find a way to work within this framework. This only needs to work in IE 5.5 or better. My problem is that the...
1
13291
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 alternative for outerHTML property in firefox. I am using th following function to display an image and alternate text behind al images of a weg page in Internet Explorer. Anybody can give solutio for same in firefox browser. function...
8
2264
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; In the right column I have a javascript link which hides the column. This is very necessary due to the width of content shown on the site at times. Clicking the link makes the scrollbars appear for no aparent reason - both horizontal by about...
2
6121
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 privilege of client's computer. But my boss doesn't want to lower the security settings and doesn't want to see the prompt dialog. I am wonder that signing the javascript can solve the problem or not. I am using the code to bypass the print dialog:
7
1675
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 <span> tags on the client, hidden from the screen by @media classes. From a dynamically built menu of what was returned, the user selects wich report they want to view/print and a little jscript .innerHTML magic happens under the hood that copies...
6
2019
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 run this javascript outside my web-browser, and save the page's text to a file? I've tried spidermonkey, but it just exits waying window is not defined.
0
8814
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8706
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8475
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8591
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6160
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5621
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4293
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2709
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1592
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.