CKEditor: pass value back to link-plugin - javascript

To insert a link to specific files I want to add a button to the link-Dialog, which opens my own php-filebrowser.
In this filebrowser I can browse specific directories to finally select a pdf-file.
By clicking on a file I want to pass the url of this file to the link-dialogs url-field. And that is the point where I do not get ahead.
The url I alert when clicking the file is the one I need.
All I need is the javascript to pass it to the opener's url-field.
I have tried several proposed solutions I found in this forum but nothing helped.
In my filebrowser I have a list of files.
Each file has a link like this one:
*filename*
This is the javascript part I tried in my filebrowser:
<script>
function passvalue(url) {
alert (url);
opener.SetValue(url, 'url');
window.close();
}
</script>
The script alerts the correct value. But the next line doesn't pass the value back.
Instead of "opener.SetValue(url, 'url');" I also tried
window.opener.CKEDITOR.tools.callFunction(ckeditorfuncnum, url);
with the ckeditorfuncnum passed to the script and
opener.SetUrl(url);
UPDATE:
it seems as if the second try ('window.opener.CKEditor...') would be the right one. Since no value is displayed in my input field, I tried to return an error message...
The error message is being displayed in the window with the CKEditor-Fields.

For everyone who might run into the same problem here is the solution:
function passvalue(url) {
var dialog = window.opener.CKEDITOR.dialog.getCurrent();
dialog.setValueOf('info', 'url', url);
dialog.setValueOf('info', 'protocol', 'http://');
window.close();
}

Related

How to use information from the URL to click on specific button?

I'm working on a group project for a class, and we have a webpage that is split into different tabs, so it is only one webpage, but appears to be different pages using Jquery so the page doesn't have to reload when switching between tabs. The problem I am having is that one of the tabs has a form to get information from the user, then after the user clicks the submit button, the info is sent to the database using php, causing the page to reload. Then depending on if the information was successfully sent to the database, there will be either "success" or "invalid" appended to the end of the URL. If the user submits this form, we want them to automatically come back to this tab on the reload, and I have tried doing this by using a script like this:
<script>
document.getElementById("baseTab").click();
window.onload = function() {
var theurl = document.location.href;
if (theurl.includes("success") || theurl.includes("invalid") {
document.getElementById("infoTab").click();
}
};
</script>
The baseTab is the tab we want to load whenever someone first loads the webpage, unless they have just submitted the form on the infoTab page. This code structure works on a simple test webpage I run on my computer, but when I try to push it to our project repository, it will only do the "baseTab".click, and not click the "infoTab" button even if theurl includes "success" or "invalid". I tried doing it without the window.onload(), but that doesn't work either. Also, if I do
if (theurl.includes("success") || theurl.includes("invalid") {
document.getElementById("infoTab").click();
}
else {
document.getElementById("baseTab").click();
}
then neither of the buttons get clicked. If their is an easier way to do this or you see where I am going wrong, any help would be appreciated. Thanks!

Clicking a menu link to bring up sign up box via js file

I have set up a pop up sign up box to show on first site arrival that is loaded using a .js file called inside the <head> tag and this all works fine.
How can i get it to re-show if a menu link is clicked?
Obviously when i link it like this below it will open the file itself containing the codes.
Mailing List
So how do i get it to carry out the function that's in popup.js when the above link is clicked?
Edit: I was able to get the pop up to show by using the below thank you all who contributed.
Mailing List
Now to complete what i'm trying to achieve is to ignore/disable the cookie being set that stops the popup from showing the next time the link is clicked.
function AlreadyBeenNewsletter()
and
function SetNewsletterCookie()
Link to the actual js file
If the JS is already included, you could use the onclick attribute. It will run JS code when a link is clicked.
Mailing List
For the second part of your question, I would create two functions. One that shows the popup without checking if the cookie is set, and another (you already have it) that checks the cookie.
Function that shows popup without checking:
function showPopup(){
var id;
id = "popupSignup";
if (jq(".popupWindow").length) {
jq(".popupWindow").prop("id", id);
} else {
jq("#aspnetForm").after('<div id="popupSignup" class="popupWindow"><a class="popupClose" href="javascript:;"></a><div class="popupDetails"></div></div><div class="backgroundPopup"></div>');
}
jq("#" + id + " .popupDetails").html('<iframe class="popupiframe" src="/user/files/newsletter.html"></iframe>');
InitialisePopup(id, 99, false, true);
ShowPopup();
CenterPopup();
}
Function that you already have popup()
jq(function popup() {
if (!AlreadyBeenNewsletter()) {
SetNewsletterCookie();
showPopup();
}
});
Then you can do the following for your link:
Mailing List
By separating the two functions apart like this you are free to show the popup without preventing it from showing again.

MVC - Loading screen / disable button before and after downloading a file

So i have a button to download a csv file. The button simple does:
$("#btnExportToContactList").click(function (e) {
window.location.href = '/Home/ExportList';
});
My action simply returns a
File(new System.Text.UTF8Encoding().GetBytes(csv), "text/csv", filename);
Everything is working fine. Now since I'm building a csv when pressing the button and since the process can take some time, I want to put up a loading screen or simply disable the button while they wait. My problem is how to disable/enable the button?
I have tried the following but it doesn't work because the browser is being redirected to another page and it will stop executing my Javascript.
$("#btnExportToContactList").click(function (e) {
$("#btnExportToContactList").attr("disabled", true);
window.location.href = '/Home/ExportList';
$("#btnExportToContactList").attr("disabled", false);
});
but its not working. Anybody have a solution for this?
You can set disabled property to false each time page is ready or loaded.
$(function(){
$("#btnExportToContactList").attr("disabled", false);
$("#btnExportToContactList").click(function (e) {
$("#btnExportToContactList").attr("disabled", true);
window.location.href = '/Home/ExportList';
});
});
Update: If above isnt working, you can try workaround like this. Rather than calling window.location.href you can call action of controller using ajax request and returning json resullt containing url of file created on server and then on success of ajax call you can download this file using some javscript code and then changing desired element's disabled property.
Check this for more

HTML onclick event not loading JavaScript function

So I'm having issues with my onclick function that I wasn't having before. When I originally implemented it on the page, it was working perfectly. Then, once I changed the location of the JS file to a subfolder in the directory, (and changed the location in my HTML) the onclick link I made stopped calling the JS function.
function namePrompt() {
var x=prompt("Enter your first and last name:");
if (x) {
window.location.href = "http://database.gchandel.com/app_edit.php?name="+x;
}
}
Above is the JS code I'm using, and below is the line that calls the function.
<a onclick="namePrompt()">click this link to view your entry.</a>
I've tried everything from moving the file back to its original location, to refreshing the page many times, to changing things like function name and file name and none of this has given me any luck.
Also, here's the link to the site I'm working on: database.gchandel.com
The problem is in your prompt syntax, check it here
Syntax of prompt is
prompt("", "");
While working one is here

How can I regain program control after <cfheader> opens a PDF file?

This is a ColdFusion 8 question.
I have a cfm page that has a button that onClick calls the following Javascript function located in the page header:
function confirm_expiration_letters() {
var resultOfConfirm = confirm("Would you like to send expiration and reminder letters?");
if (resultOfConfirm == true) {
document.body.style.cursor = "wait";
window.location="_expiration_letters.cfm";
}
}
On the page that is called, a series of emails are generated, then a PDF report file is generated and displayed using these two lines:
<cfheader name="Content-disposition" value="attachment;filename=#fileName#">
<cfcontent type="application/pdf" file="#docPath#/#fileName#" deletefile="true">
Notice in the JS function that the cursor is changed to "wait". But the program control appears to get lost after the above cfheader call and so I can't find anywhere that I can reset the cursor back to:
document.body.style.cursor = "default";
Do you have ideas on where I can place this to turn off the cursor animation? I tried multiple places and it doesn't work. Once the cfheader and cfcontent calls happen, control of previous window and cursor are lost it appears.
You might try something like this above the cfheader.
<script>
document.body.style.cursor = "default";
</script>
<cfflush/>
The problem is that doing so might (probably will) screw up the cfheaders since cfflush is designed to flush partial results and will include the headers. But it's the only thing I can think of.
If I understand you correctly, you want to have a "wait" cursor whilst the PDF is prepped, and then return to a standard cursor after that.
Don't web browsers do this automatically when you're waiting for a requested document? IE: as soon as you do your window.location, whilst the document is loading, the cursors automatically changes to a "wait", and then once the doc is served, returns to an "auto".
This is what I see (when running code similar to yours). Is this not what you see?
Instead of changing the cursor, display a loading message using HTML/animated gif. When the PDF loads, it will replace the loading screen.
I would suggest having a hidden div containing your loading message, then use JavaScript to make it appear when needed.
Here's some JavaScript. This is how it would be done with jQuery.
function confirm_expiration_letters() {
var resultOfConfirm = confirm("Would you like to send expiration and reminder letters?");
if (resultOfConfirm == true) {
$('#Loading').fadeIn(); //SHOW THE LOADING INDICATOR
$.post('PDFGenerator.cfm', function(returnData){ // AJAX POST, CALLBACK
//RETURN THE FILENAME OR LOCATION OF THE PDF
var FileName = $.trim(returnData); // TRIM THE RETURNED DATA
window.open("path_to_file/" + FileName,"_blank"); // NEW WINDOW
$('#Loading').fadeOut(); // HIDE THE LOADING INDICATOR
});
}
}

Categories