Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3696150
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:42:14+00:00 2026-05-19T04:42:14+00:00

I have the following inline Javascript code: <a href=javascript:{ document[‘example’].src = ‘cube.png’; document.getElementById(‘constructor’).innerHTML =

  • 0

I have the following inline Javascript code:

<a href="javascript:{ document['example'].src = 'cube.png'; document.getElementById('constructor').innerHTML = 'Mesh mesh = new Mesh.Cube();'; }">Cube</a>

For your poor tired programmer eyes, here’s the expanded version:

document['example'].src = 'cube.png';
document.getElementById('constructor').innerHTML = 'Mesh mesh = new Mesh.Cube();';

This code acts as a hyperlink that changes the example image to an image of a 3D cube and changes a <pre id="constructor">‘s content to the appropriate constructor. (This is obviously a tutorial page).

This works perfectly fine in Chrome, but in other browsers, I get either a new page or the whole page’s content changed to:

Mesh mesh = new Mesh.Cube();

What is the problem with the code? What puzzles me is that it’s valid in a browser and not in another. It’s as if the script couldn’t find the ‘constructor’ element and proposed the whole page as a fallback. I’m far from being a Javascript expert, so that’s just a wild guess.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:42:15+00:00Added an answer on May 19, 2026 at 4:42 am

    I will just answer “What is the problem with the code?”

    The href behaves differently than any onXXX event (hence javascript: protocol). It kind of tries to load new document and put something inside. The worst thing, it catches all output. So, to make it work as-is, you need to catch all statement values as assignments:

    
    var x = document['example'].src = 'cube.png';
    var y = document.getElementById('constructor').innerHTML = 'Mesh mesh = new Mesh.Cube();';
    

    all in javascript:{...} of course.

    Also some good comments and explanations here: http://www.west-wind.com/weblog/posts/9899.aspx

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code <a href=#inline class=fancy id=item1>hello item1</a> <a href=#inline class=fancy id=item2>hello
So I have the following code: <script type=text/javascript> $(document).ready( function () { $(#txt).click(function ()
I have this following code - <html> <head> <title>Rebound</title> <script src=http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js></script> <script type=text/javascript> function
I have the following inline javascript, im using a jquery countdown plugin to display
The following practice is fairly commonplace in the inline JavaScript I have to work
I have the following function: inline auto iterateSomething(obj & o) { auto iterators =
I have the following div <body> <span style=border:1px solid red; display:inline-block> Some text<br />
Hi i have the following <label> <INPUT style=DISPLAY: inline; VERTICAL-ALIGN: middle class=fieldValue name=radioOpt value=1
Suppose I have the following HTML: <div id=test> <span style=display:inline;>foo</span> <span style=display:none;>bar</span> <span style=display:inline;>baz</span>
Let's say I have the following HTML code <div id="outer"> <div id="inner">Hello World</div> </div>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.