2009-11-01 12 views
11

ठीक कहता है, मैं इस समस्या पर कुछ समय बिताया है और इस मैं क्या इकट्ठा किया है:इंटरनेट एक्सप्लोरर window.open और AJAX पर window.onbeforeunload बुला

  1. आप IE7 में एक AJAX कॉल करते हैं और आपके पास एक window.onbeforeunload फ़ंक्शन निर्दिष्ट है, यह onbeforeunload फ़ंक्शन को कॉल करता है।

  2. यदि आप विंडो के साथ एक नई विंडो खोलने का प्रयास करते हैं तो वर्तमान विंडो को परेशान किए बिना, ऑनबेरनलोड को कॉल किया जाता है।

क्या किसी को यह पता है कि इसे कैसे रोकें? मैंने एक वैरिएबल को TRUE पर सेट करने का प्रयास किया और उस चर को अपने ऑनबर्ननलोड फ़ंक्शन में जांचें और यह अभी भी काम कर रहा है! मुझे बस उस विधि के निष्पादन को AJAX कॉल और नई विंडो कॉल के लिए रोकने में सक्षम होना चाहिए।

+0

बस देखा एक ही समस्या! डब्ल्यूटीएफ आईई 7 कॉलिंग विंडो कर रहा है। जब आप एक नई विंडो खोलते हैं और वर्तमान एक अपरिवर्तित होता है तो पहले से लोड करें! मैं विश्वास नहीं कर सकता ..... –

+0

वास्तव में! लेकिन आप आईई एक्सडी से और क्या उम्मीद कर सकते हैं ... और आईई 8 में समस्या अभी भी है। – agentfll

+0

हाँ, मैंने इसमें भी भाग लिया है। IE8 – Jon

उत्तर

7

एक और और शायद सरल विकल्प है जब आप पॉपअप खोलने झूठी वापस जाने के लिए है। अन्य सभी विकल्प मेरे लिए विशेष रूप से व्यवहार्य नहीं थे।

0

क्या आपने window.open पर कॉल करने से पहले "onbeforeunload" ईवेंट से हैंडलर को हटाने का प्रयास किया था? यह मदद कर सकता है लेकिन मैंने कभी इसका परीक्षण नहीं किया।

1

मुझे लगा कि आपको खिड़की को अनसेट करने की आवश्यकता है। कुछ भी करने से पहले इसे पहले से लोड करें और फिर जब आप पूरा कर लें तो इसे वापस रखें।

मैंने अभी आईई में सुविधा को अक्षम कर दिया है।

3

ठीक है, मुझे यह समस्या है। मेरे पास इसके लिए एक (बल्कि गन्दा) काम है।

मेरे मामले में, मैं कभी-कभी नेविगेशन को अवरुद्ध करना चाहता हूं, न कि दूसरों को।

तो, मैं खिड़की पर एक ध्वज सेट कर रहा हूं ताकि मुझे यह बताने के लिए कि क्या मैं इसे अवरुद्ध करना चाहता हूं। तो जहां आप अपनी खिड़की कर रहे हैं। ओपन, बस इससे पहले, 'window.allowExit = true' करें, फिर onforeforeload में, window.allowExit = true के लिए जांचें।

मैं जावा स्क्रिप्ट (SHowHelp) एक लिंक से शुरू हुआ जा रहा है:

<a href="javascript:ShowHelp('argument')" >HERE</a> 

onbeforeunload ShowHelp से पहले कहा जाता है, तो मैं झंडा

<a onclick="window.allowExit = true;" href="javascript:ShowHelp('argument')" >HERE</a> 

बदसूरत स्थापित करने के लिए इस्तेमाल किया onclick पाप के रूप में, लेकिन ऐसा लगता है!

2

यह कोई समाधान नहीं है, लेकिन रुचि रखने वाले किसी भी व्यक्ति के लिए स्पष्टीकरण। मैंने अभी आईई 7 में एक त्वरित परीक्षण चलाया है, और जब भी एचआरईएफ एक ही पृष्ठ पर जाता है तब तक यह एक बार क्लिक किया जाता है जब तक एक लिंक क्लिक नहीं किया जाता है: यानी जब तक इसमें # नहीं होता है। तो मेरा अनुमान है कि आईई इंजीनियरों को यह सोच रहा था कि जब कोई उस पृष्ठ पर क्लिक करता है जो पृष्ठ पर कहीं और नहीं है, तो उन्हें पृष्ठ छोड़ना होगा, इस मामले में पृष्ठ अनलोड करने वाला है। कहने की जरूरत नहीं है, इस सोच के साथ स्पष्ट समस्याएं हैं।

<a onclick="window.open(...); return false;" href="javascript:;" >my link</a> 

यह आपको पेज छोड़ रहे हैं सोच और घटना पर आरंभ होने से आईई को रोकने के लिए लगता है:

1

मुझे एक ही समस्या थी, मेरे मामले में सभी अनुरोध AJAX कॉल से आते हैं, यह समाधान को सरल बनाता है, क्योंकि जब मैंने मानक बटन के साथ porblem को ठीक किया, तो मैंने अपने केंद्रीकृत फ़ंक्शन पर सभी ऑनक्लिक को रीडायरेक्ट करने के लिए एक पुनरावर्ती फ़ंक्शन किया, फिर एक विवाद कठोर क्लिक करें। मैं AJAX कॉल suporting href समस्या के लिए समाधान की प्रतिलिपि बना रहा हूं। यह समाधान पिछले पृष्ठ पर लौटने से बचता है। एक फ़ाइल का नाम backbutton अंदर कोड रखो, जे एस कोई भी टिप्पणी लिखने विषय के साथ [email protected] करने के लिए: जावास्क्रिप्ट backbutton

<!-- backbutton developed by Manuel Parma 2011-06-10 --> 
<!-- email: [email protected] --> 
<!-- Add the next line into the <body> section as a first line --> 
<!-- <script type="text/javascript" src="<path>/backbutton.js"></script> --> 

<!-- Address used when backtoLogin is 1 or when there is not previous page from site --> 
var returningAddress = "http://my returning address" 

<!-- Message to display when an external action (back button, forward button, backspace) move without press the application buttons --> 
var backButtonMessage = "Using the browser's Back button may cause a loss in data. Please use the Back and Continue buttons at the bottom of the form." 

<!-- 0=no/1=yes (assume per default that the back button will be pressed --> 
<!--    and come into action if this was NOT the case)   --> 
var backButtonPressed = 1;  

<!--This var when is setted to 1 avoid to captureEvent set backbuttonPressed to 1, otherwise unload event cannot detect the right state of backButtonPressed--> 
var onbeforeunloadeventFired = 0; 

<!--Indicate to logic back to first page (login) when its value is 1 otherwise the logic back to previous page out of the site--> 
var backtoLogin = 0; 
var DoPostBackWithOptionsHook = null; 
var DoPostBackHook = null; 


<!-- Check the previous status --> 
if (window.name == ""){ 
    <!-- When window.name is empty, this is indicating the first call of site --> 
    window.name = "L0001"; 
} 
else { 
    if (window.name == "L0000_back"){ 
     <!-- In this condition the page is returning after a foward button press --> 
     setBackButton(0); 
     window.name = ""; 

     <!-- the system reload the page to clean the data --> 
     window.location.href = returningAddress; 
    } 
    else { 
     if (window.name.indexOf("_back") > 4){ 
      <!-- when the word back is present, the previous call is sending a message that the back button was pressed and the site is going out --> 

      <!-- get the internal counter --> 
      var sLastValue = modifynamevalue(0);  

      <!-- set the count to go back --> 
      var iCountBack = -(sLastValue * 1); 
      if (backtoLogin == 1) {iCountBack++;}; 

      if (window.history.length - 2 < -iCountBack) { 
       iCountBack = -(window.history.length - 2); 
      } 

      <!-- the site is flag that first page needs to reload --> 
      window.name = "L0000_back";    
      setBackButton(0); 

      <!-- the site is returning to the first page or previous --> 
      window.history.go(iCountBack); 
     } 
     else { 
      <!-- increase the internal counter --> 
      var sLastValue = modifynamevalue(+1); 
      window.name = "L" + sLastValue; 
     } 
    } 
} 

<!-- Set the events needed to manage the back and forwar button situations --> 

$(document).ready(function(){ 
    if (typeof(Sys) == "object") { 
     Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest); 
     Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequest); 

     window.onbeforeunload = onbeforeunloadEvent; 
     window.onunload = unloadEvent; 
     DoPostBackWithOptionsHook = WebForm_DoPostBackWithOptions; 
     WebForm_DoPostBackWithOptions = WebForm_DoPostBackWithOptionsHook; 

     doPostBackHook = __doPostBack; 
     __doPostBack = __doPostBackHook; 

    } 

    }); 

function WebForm_DoPostBackWithOptionsHook(options) { 
    setBackButton(0); 
    return DoPostBackWithOptionsHook(options) 
} 

function __doPostBackHook(eventTarget, eventArgument) { 
    if (backButtonPressed == 1) { 
     setBackButton(0); 
    } 
    return doPostBackHook(eventTarget, eventArgument) 
} 

function beginRequest(sender, args) { 
    setBackButton(0); 
    <!-- setting onbeforeunloadeventFired = 1 I take care to avoid anyone changed the Backbutton until endrequest --> 
    onbeforeunloadeventFired = 1; 
} 


function endRequest(sender, args) { 
    onbeforeunloadeventFired = 0; 
    setBackButton(1); 
} 

<!-- unload event handler --> 
function unloadEvent(evt) { 
    <!-- double coundition using onbeforeunloadeventFired == 1 garantee avoid problemas with redirect operations --> 
    if ((backButtonPressed == 1) && (onbeforeunloadeventFired == 1)) { 
     <!-- decrement the internal counter --> 
     var sLastValue = modifynamevalue(-1); 
     window.name = "L" + sLastValue + "_back"; 
    } 

    if (DoPostBackWithOptionsHook !== null) { 
     WebForm_DoPostBackWithOptions = DoPostBackWithOptionsHook; 
    }; 

    if (doPostBackHook !== null) { 
     __doPostBack = doPostBackHook; 
    }; 
} 

<!-- on before unload --> 
function onbeforeunloadEvent(evt) { 
    onbeforeunloadeventFired = 1; 
    if (backButtonPressed == 1) { 
     return backButtonMessage; 
    }; 
} 


<!-- used to set right backButtonPressed--> 
function setBackButton(value){ 
    if (value == 0) { 
     backButtonPressed = 0; 
    } 
    else { 
     if (onbeforeunloadeventFired == 0) { 
      backButtonPressed = 1; 
     } 
    } 
} 


<!-- increment and decrment the internal counter stored into windows.name --> 
function modifynamevalue(iIncrement){ 
    var iCount = (window.name.substring(1, 5) * 1) + iIncrement; 

    if (iCount < 0) { 
     iCount = 0; 
    } 

    var sNewValue = iCount.toString(); 

    sNewValue = "0000".substring(0, 4 - sNewValue.length) + sNewValue; 
    return sNewValue; 
} 
0

यह बहुत संभव कर सकता है आपकी समस्या का समाधान!

क्योंकि मैं एक ऐसी ही समस्या और इस बनाया जाने तरीका था!

window.onbeforeunload = warnFunction; 
var warnRequired = true; 
function warnFunction() { 
    if (warnRequired) return ("Please Stay! Don't go!"); 
    return ; 
} 

और जब भी मैं अजाक्स कॉल करता हूं या पॉपअप करता हूं, तो मैं सिर्फ चेतावनी सेट करता हूं।

एक अन्य बात यह है कि सिर्फ जागरूक जब एक अजाक्स कॉल है कि यह किसी और सिंक्रनाइज़ चर अभी तक निर्धारित किया गया है नहीं हो सकता है कर रही है हो सकता है! (ए बुरा पकड़ लिया!)

1

Sid_M एक वैध बिंदु, ब्राउज़र की है कि डिजाइन हम तदनुसार हमारे आवेदन डिजाइन करने के लिए है के साथ कहा।

क्यों एंकर टैग के लिए जाने के लिए पॉपअप विंडोज़ के लिए & href, बस लेबल या यहाँ तक कि टीडी टैग में onclick विधि का उपयोग करें और फोन window.open

अपने आवेदन में से एक से सरल उदाहरण

<td class="popuplink" onMouseOver="this.style.cursor='hand'" onclick="javascript:openMe('img/howitworks.png', 'pndpopup', 600,650)"><u> How it works</u></td> 
संबंधित मुद्दे