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 8675539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:58:28+00:00 2026-06-12T19:58:28+00:00

I am implementing a bookmarklet which communicates with a iframe through a JSON-RPC protocol.

  • 0

I am implementing a bookmarklet which communicates with a iframe through a JSON-RPC protocol.

However some sites, such as cnn.com load JSON2 into window.JSON although the browser already has a native JSON object.

The problem is that within my iframe I would not like to follow the same bad practice, and JSON2 does not seem to be compatible with the native JSON on Mozilla Firefox and Chrome:

So when I run stringify on the native JSON and JSON2, I get the following results:

JSON.stringify({key: "value"})

JSON2

{key:"value"}

Native JSON

{"key":"value"}

(Key is wrapped in ")


The problem is that the native JSON does not like it when the " is missing in the JSON2-produced string and throws an error:

Mozilla Firefox: SyntaxError: JSON.parse: expected property name or '}'

Google Chrome: SyntaxError: Unexpected token k

To solve the problem for good, I need to make sure that I use the same JSON library to encode the string as I do for decoding it.

One way of doing it is to make sure to use JSON2 or JSON3 on both sides, but I’d like to use the native json library where possible.

So now that sites like cnn.com have overriden the native JSON library, how can I get back to it?

I could perhaps create an iframe that points to the same domain and fetch the JSON object from its contentWindow, but that would be highly inefficient.

Isn’t there a better way?

  • 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-06-12T19:58:29+00:00Added an answer on June 12, 2026 at 7:58 pm

    not sure if i understand your problem correctly

    if you place an empty iframe like this

    <iframe id="testFrame" name="testFrame" src="about:blank" style="display:none;"></iframe>
    

    then you can also call from js

    testFrame.JSON.stringify(obj);
    

    the only problem is that if you use it in https: src could be javascript:false if you need to support IE6

    EDIT: I still think i don’t deserve the answer being accepted, so i’ve come up with a modified version of your code

    (function($) {
      var frm;
      $.getNative = function(objectName, callback) {
        if (!frm) {
          frm= $("<iframe>", {
            src: "javascript:false",
            style: "display:none;"
          }).appendTo("body").load(function(){
            callback(this.contentWindow[objectName]);
            // $(this).remove(); <-- this is commented to cache the iframe
          });
        }
        callback(frm[0].contentWindow[objectName]);
      }
    })(jQuery)
    

    this will enable you to use $.getNative() multiple times in a document without recreating the frame each time.

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

Sidebar

Related Questions

Implementing a custom membership provider, there are certain properties such as MinRequiredPasswordLength that only
When implementing the Strategy Pattern, where does one put the code that determines which
How would I go about implementing this as a bookmarklet? This is the function
Im implementing my own RPC framework and well moste of the stuff is done
While implementing my own IFilter I found that most likely some consumers will require
Implementing the very first scala example I ran into some problems probably tipical for
When implementing a Facebook Canvas app using an iframe the iframe does a post
When implementing a Matrix construct using arrays, which would be more efficient? Using a
While implementing Multithreaded Cache, i found this article on MSDN. http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim.aspx This is for
When implementing SuperBoxSelect (http://www.sencha.com/forum/showthread.php?69307-3.x-Ext.ux.form.SuperBoxSelect), I've realized that it currently does not support shift +

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.